﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarchEstate.Manager.BusinesEntity;
using MarchEstate.Manager.Dao.Costform;
using CoreFrame.Core.Orm;
using MarchEstate.Manager.BusinesEntity.Costcalculate;

namespace MarchEstate.Manager.ObjectModel.Costform
{
    public class MeterOrder : AbstractMeterOrder
    {
        private CostformDao formDao = null;

        public MeterOrder()
        {

        }
        public override void InitDao()
        {
            base.InitDao();
            formDao = NewDao<CostformDao>();
        }


        public override bool Save()
        {
            if (MeterOrderId == null)
                formDao.AddMaterOrder(this);
            else
                formDao.UpdateMaterOrder(this);
            return true;
        }

        public override bool Delete(string _meterOrderId)
        {
            return formDao.DeleteMeterOrder(_meterOrderId);
        }

        public override List<AbstractMeterOrder> GetMeterOrderList(string _meterHeadId)
        {
            return formDao.GetMeterOrderList(_meterHeadId);
        }

        public override List<AbstractMeterOrder> GetMeterOrderList(string _meterHeadId, PageInfo page)
        {
            return formDao.GetMeterOrderList(_meterHeadId, page);
        }

        public override AbstractMeterOrder UpdateMeterformResult(string meterOrderId, decimal thisNum)
        {
            AbstractMeterOrder order = formDao.GetMeterOrder(meterOrderId);
            order.ThisNum = thisNum;
            order.MeterNum = order.ThisNum - order.LastNum;


            AbstractMeterAlgorithmic meter = NewObject<AbstractMeterAlgorithmic>("meter");
            meter.Lastdegree = order.LastNum;
            meter.Currentdegree = order.ThisNum;
            meter.Unitprice = formDao.GetMeterPrice(order.MeterId);

            order.Thiscost = meter.GetItemFee();
            order.InitDao();
            order.Save();

            return order;
            //throw new NotImplementedException();
        }



        
    }
}
